#include "FsTypes.h"
#include "mConfig.h"
#include "Config.h"
#include "Utils.h"
#include "RAT.h"
#include "Sram.h"


static UINT32 SramBuffer[SRAM_SIZE_TOTAL / sizeof(UINT32)] = {0};

UINT8 *GetSramPtr(void)
{
	return ((UINT8*)SramBuffer);
}

UINT8 CreateSramTable(UINT16 nSize)
{
	if(nSize > SRAM_CLUS_SIZE * MAX_RAT_NUM)
	{
		return (0);
	}

	CreateRAT(nSize / SRAM_CLUS_SIZE, SRAM_CLUS_NOUSED);

	return (1);
}

UINT8 GetSramClusSize(void)
{
	return (SRAM_CLUS_SIZE);
}

UINT16 GetSramTotalSize(void)
{
	return (SRAM_SIZE_TOTAL);
}

void SramClusEmpty(UINT8 ClusID)
{
	UINT8 *p = (UINT8*)SramBuffer;

	EmptyBytes(&p[ClusID * SRAM_CLUS_SIZE], SRAM_CLUS_SIZE);

	return ;
}

UINT8 *SramClusConvPtr(UINT8 ClusID)
{
	UINT8 *p = (UINT8*)SramBuffer;
	UINT16 nRats = GetRATTotal();

	ClusID = (ClusID > nRats) ? (nRats - 1) : ClusID;

	return (&p[ClusID * SRAM_CLUS_SIZE]);
}

UINT16 GetSramFree(void)
{
	return (GetRATFree() * SRAM_CLUS_SIZE);
}
